package lambda;

import java.util.function.Function;

public class FunctionDemo {
    public static void main(String[] args) {
        //convert("100", s -> Integer.parseInt(s));
        //convert("1222",Integer::parseInt);

        convertInt(100, integer -> {
            integer += 10;
            return String.valueOf(integer);
        });

        convert("123", s -> {
            return Integer.parseInt(s);
        }, integer -> {
            return String.valueOf(integer + 10);
        });

        slid("lqx,23", s -> {
            return Integer.parseInt(s) + 70;
        });
    }

    // int  integer 可以子哦对那个装箱和拆箱
    private static void convert(String s, Function<String, Integer> function) {
        Integer apply = function.apply(s);
        System.out.println(apply);
    }

    private static void convertInt(Integer in, Function<Integer, String> function) {
        System.out.println(function.apply(in));
    }

    private static void convert(String s, Function<String, Integer> fun1, Function<Integer, String> fun2) {
        String apply = fun1.andThen(fun2).apply(s);
        System.out.println(apply);
    }

    private static void slid(String string, Function<String, Integer> function) {
        String[] split = string.split(",");
        Integer apply = function.apply(split[1]);
        System.out.println(apply);
    }
}
